﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleTaskManager.Domain.Concrete;
using SimpleTaskManager.Domain.Entities;

namespace SimpleTaskManager.Domain.SampleData
{
    /// <summary>
    /// Containes a static method to add initial data to the database
    /// </summary>
    public class Initializer
    {
        /// <summary>
        /// Indicates whether the application is running for the first time.
        /// </summary>
        /// <param name="context">The database context.</param>
        /// <returns>True if the application is launched for the first time.</returns>
        public static bool IsFirstRun(EFDbContext context)
        {
            return !(context.Users.Any(u => !u.Login.Equals("baseUser")));
        }

        /// <summary>
        /// Adds some initial data to the database context specified.
        /// </summary>
        /// <param name="context">The database context to which data will be added</param>
        public static void InitializeData(EFDbContext context)
        {
            #region Users
    #if !DEBUG
            DateTime startingDate = DateTime.Now;
    #endif
    #if DEBUG
            // Some sample data
            DateTime startingDate = DateTime.Now.AddMonths(-9); //the company is 9 months old
            List<String> names = new List<string>{"John", "Monica", "Mike", "Paul", "Edward", "Eva", "Angelica",
            "Jack", "Thomas", "Joshua", "William", "Daniel", "Matthew", "Harry", "Joseph", "Samuel", "Emily", "Chloe", "Megan",
            "Jessica", "Emma", "Sarah", "Elizabeth", "Sophie", "Olivia"};
            List<String> surnames = new List<string> {"Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", 
                "Wilson", "Moore", "Taylor", "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin", 
                "Thompson", "Garcia", "Martinez", "Robinson"};
            List<String> cities = new List<string> {"New York", "Jersey City", "Newark", "Paterson", "Paramus", "Perth Amboy", "Stamford", "Trenton" };
            Dictionary<String, String> addressLines = new Dictionary<string, string> { {"Ann Street", "13222"}, {"Beach Street", "13421"}, {"Bleecker Street", "12487"},
                {"Hester Street", "09421"}, {"Fulton Street", "09323"}, {"Lincoln Square", "12499"}, {"Lincoln Street", "04951"}, 
                {"Lincoln Avenue", "09712"}, {"Francis Lewis Boulevard", "10840"} };
            List<String> availablePositions = new List<string> {"Junior Developer", "Developer", "Senior Developer", "Software tester", "Office help"}; 
            int howManyUsers = 70;
            var WorkingHourEntries = new List<WorkingHoursEntry>();

            List<User> autoCreatedUsers = new List<User>();
            var adminUser = new User
            {
                Login = "admin",
                Password = "e8f97fba9104d1ea5047948e6dfb67facd9f5b73", //password
                CreationDate = startingDate,
                DateOfBirth = DateTime.Parse("1980-01-01"),
                Role = UserRole.SuperUser,
                FirstName = "John",
                LastName = "Adams",
                Address = "Ann Street 1",
                City = "New York",
                ZIP = "13222",
                Country = "U.S.",
                Email = "admin@stm-example.com",
                Position = "Administrator",
                PersonalIdentifier = "1"
            };
            autoCreatedUsers.Add(adminUser);
            //Create worked hours
            Random random = new Random();

            int maxhours = random.Next(81) + 20;
            for (int j = 0; j < maxhours; j++)
            {
                var workingHour = new WorkingHoursEntry
                {
                    Hours = random.Next(4) + 5,
                    User = adminUser,
                    Date = adminUser.CreationDate.AddDays(
                        random.Next(Convert.ToInt32(Math.Floor(new TimeSpan(DateTime.Now.Ticks - adminUser.CreationDate.Ticks).TotalDays))))
                };
                WorkingHourEntries.Add(workingHour);
            }

            

            //generate Random Users
            
            for (int i = 1; i < howManyUsers; i++)
            {
                int bossIndicator = random.Next(69) % 23;
                int addressIndex = random.Next(addressLines.Count);
                User newUser = new User {
                    PersonalIdentifier = (i+1).ToString(),
                    Password = "6ed5833cf35286ebf8662b7b5949f0d742bbec3f", //123456
                    CreationDate = startingDate.AddMonths(i/10), //we add 10 employees each month
                    DateOfBirth = DateTime.Parse("1950-01-01").AddMonths(random.Next(12*35)).AddDays(random.Next(28)),
                    Position = (bossIndicator == 0 ) ? "Boss" : availablePositions[random.Next(availablePositions.Count)],
                    Role = (bossIndicator == 0) ? UserRole.Manager : UserRole.Worker,
                    FirstName = names[random.Next(names.Count)],
                    LastName = surnames[random.Next(surnames.Count)],
                    Login = "user" + (i + 1).ToString(),
                    Address = addressLines.ElementAt(addressIndex).Value,
                    City = cities[random.Next(cities.Count)],
                    ZIP = addressLines.ElementAt(addressIndex).Key,
                    Country = "U.S.",
                    Status = (i % 12 == 0) ? StatusEnum.InActive : (i % 9 == 0) ? StatusEnum.OnALeave : StatusEnum.Hired 
                    
                };
                newUser.Email = String.Format("{0}.{1}@stm-example.com", newUser.FirstName.ToLower(), newUser.LastName.ToLower());
                //Create worked hours
                int hours = random.Next(81) + 20;
                for (int j = 0; j < hours; j++)
                {
                    var workingHour = new WorkingHoursEntry
                    {
                        Hours = random.Next(4) + 5,
                        User = newUser,
                        Date = newUser.CreationDate.AddDays(
                            random.Next(Convert.ToInt32(Math.Floor(new TimeSpan(DateTime.Now.Ticks - newUser.CreationDate.Ticks).TotalDays))))
                    };
                    WorkingHourEntries.Add(workingHour);
                }
                autoCreatedUsers.Add(newUser);
            }
            autoCreatedUsers.ForEach(u => context.Users.Add(u));
            context.SaveChanges();

           /* var user = new User
            {
                Login = "admin",
                Password = "e8f97fba9104d1ea5047948e6dfb67facd9f5b73", //password
                CreationDate = DateTime.Now,
                DateOfBirth = DateTime.Parse("1980-01-01"),
                Role = UserRole.SuperUser,
                FirstName = "John",
                LastName = "Adams",
                Address = "Grunwaldzka 23",
                City = "Wroclaw",
                ZIP = "50552",
                Country = "Poland",
                Email = "john@adams.com",
                Position = "Administrator",
                PersonalIdentifier = "111"
            };
            var user2 = new User
            {
                Login = "mike",
                Password = "6ed5833cf35286ebf8662b7b5949f0d742bbec3f", //123456
                CreationDate = DateTime.Now,
                DateOfBirth = DateTime.Parse("1975-01-01"),
                Role = UserRole.Worker,
                FirstName = "Mike",
                LastName = "Bush",
                Address = "Grunwaldzka 23",
                City = "Wroclaw",
                ZIP = "50552",
                Country = "Poland",
                Email = "john@adams.com",
                Position = "Employee",
                PersonalIdentifier = "111"
            };
            var user3 = new User
            {
                Login = "alice",
                Password = "6ed5833cf35286ebf8662b7b5949f0d742bbec3f", //123456
                CreationDate = DateTime.Now,
                DateOfBirth = DateTime.Parse("1985-01-01"),
                Role = UserRole.Worker,
                FirstName = "Alice",
                LastName = "Adams",
                Address = "Grunwaldzka 23",
                City = "Wroclaw",
                ZIP = "50552",
                Country = "Poland",
                Email = "john@adams.com",
                Position = "Employee",
                PersonalIdentifier = "111"
            };

            var user4 = new User
            {
                Login = "john",
                Password = "6ed5833cf35286ebf8662b7b5949f0d742bbec3f", //123456
                CreationDate = DateTime.Now,
                DateOfBirth = DateTime.Parse("1970-01-01"),
                Role = UserRole.Worker,
                FirstName = "John",
                LastName = "Adams",
                Address = "Grunwaldzka 23",
                City = "Wroclaw",
                ZIP = "50552",
                Country = "Poland",
                Email = "john@adams.com",
                Position = "Employee",
                PersonalIdentifier = "111"
            };

            var user5 = new User
            {
                Login = "bob",
                Password = "6ed5833cf35286ebf8662b7b5949f0d742bbec3f", //123456
                CreationDate = DateTime.Now,
                DateOfBirth = DateTime.Parse("1962-02-02"),
                Role = UserRole.Worker,
                FirstName = "Bob",
                LastName = "Adams",
                Address = "Grunwaldzka 23",
                City = "Wroclaw",
                ZIP = "50552",
                Country = "Poland",
                Email = "john@adams.com",
                Position = "Employee",
                PersonalIdentifier = "111"
            };


            var Users = new List<User>
            {
                user,
                new User { Login = "THEboss", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1980-01-01"), Role = UserRole.Manager, 
                                FirstName="Vito", LastName="Corleone", Address="Grunwaldzka 23", City="Wroclaw", ZIP="50552", Country="Poland", Email="john@adams.com",
                                Position="Boss", PersonalIdentifier="111", Status = StatusEnum.Hired}, 
                new User { Login = "employee1", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1970-01-01"), Role = UserRole.Worker, 
                                FirstName="Mike", LastName="Johnson", Address="Sienkiewicza 12", City="Wroclaw", ZIP="50512", Country="Poland", Email="mike@example.com",
                                Position="Employee", PersonalIdentifier="11123", Status = StatusEnum.Hired}, 
                new User { Login = "employee2", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1983-05-01"), Role = UserRole.Worker, 
                                FirstName="Monica", LastName="Bing", Address="Sienkiewicza 12", City="Wroclaw", ZIP="50512", Country="Poland", Email="monica@example.com",
                                Position="Employee", PersonalIdentifier="11231", Status = StatusEnum.Hired},
                new User { Login = "employee3", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1982-01-07"), Role = UserRole.Worker, 
                                FirstName="Paul", LastName="Rooney", Address="Rynek 11", City="Wroclaw", ZIP="50500", Country="Poland", Email="paul@example.com",
                                Position="Employee", PersonalIdentifier="114531", Status = StatusEnum.Hired}, 
                new User { Login = "employee4", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1987-03-11"), Role = UserRole.Worker, 
                                FirstName="John", LastName="Johnson", Address="Nowaka 1/23", City="Wroclaw", ZIP="54521", Country="Poland", Email="john@example.com",
                                Position="Employee", PersonalIdentifier="112561", Status = StatusEnum.Hired}, 
                new User { Login = "employee5", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1980-01-08"), Role = UserRole.Worker, 
                                FirstName="Alex", LastName="Bush", Address="Na Grobli 14/3", City="Wroclaw", ZIP="52698", Country="Poland", Email="alex@example.com",
                                Position="Employee", PersonalIdentifier="13611", Status = StatusEnum.Hired}, 
                new User { Login = "employee6", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1980-08-01"), Role = UserRole.Worker, 
                                FirstName="Chandler", LastName="Bing", Address="Armii Krajowej 20", City="Wroclaw", ZIP="50554", Country="Poland", Email="chandler@example.com",
                                Position="Employee", PersonalIdentifier="11563431", Status = StatusEnum.Hired}, 
                new User { Login = "employee7", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1986-04-02"), Role = UserRole.Worker, 
                                FirstName="Joey", LastName="Tribiani", Address="Kazimierza Wielkiego 19/2", City="Wroclaw", ZIP="50697", Country="Poland", Email="joey@example.com",
                                Position="Employee", PersonalIdentifier="123235611", Status = StatusEnum.Hired}, 
                new User { Login = "employee8", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1977-02-04"), Role = UserRole.Worker, 
                                FirstName="Ross", LastName="Owen", Address="Mickiewicza 11", City="Wroclaw", ZIP="50777", Country="Poland", Email="ross@example.com",
                                Position="Employee", PersonalIdentifier="47343111", Status = StatusEnum.Hired}, 
                new User { Login = "employee9", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1987-11-11"), Role = UserRole.Worker, 
                                FirstName="Frodo", LastName="Baggins", Address="Grunwaldzka 2/2", City="Wroclaw", ZIP="50552", Country="Poland", Email="frodo@example.com",
                                Position="Employee", PersonalIdentifier="11677531", Status = StatusEnum.Hired}, 
                new User { Login = "employee10", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1975-01-11"), Role = UserRole.Worker, 
                                FirstName="Chris", LastName="Adams", Address="Serbska 4", City="Wroclaw", ZIP="50666", Country="Poland", Email="chris@example.com",
                                Position="Employee", PersonalIdentifier="12211", Status = StatusEnum.Hired},
                new User { Login = "employee11", Password="6ed5833cf35286ebf8662b7b5949f0d742bbec3f", CreationDate=DateTime.Now, DateOfBirth=DateTime.Parse("1988-06-12"), Role = UserRole.Worker, 
                                FirstName="Adam", LastName="Ayers", Address="Mickiewicza 87", City="Wroclaw", ZIP="50777", Country="Poland", Email="adam@example.com",
                                Position="Employee", PersonalIdentifier="11567341", Status = StatusEnum.Hired}
            };
            var group = new List<User>
            {
                user4,
                user2,
                user3
            };
            var group2 = new List<User>
            {
                user5,
                user3
            };
            Users.ForEach(u => context.Users.Add(u));
            context.SaveChanges();
            * */
#endif
            #endregion
            #region Projects
            var baseUser = new User();
            baseUser.Login = "baseUser";
            baseUser.Password = "baseUserStrongPassword";
            baseUser.Address = "unknown";
            baseUser.City = "unknown";
            baseUser.Country = "unknown";
            baseUser.CreationDate = DateTime.Now;
            baseUser.DateOfBirth = new DateTime(2000, 1, 1);
            baseUser.Email = "un@kno.wn";
            baseUser.FirstName = "base";
            baseUser.LastName = "user";
            baseUser.PersonalIdentifier = "unknown";
            baseUser.Position = "unknown";
            baseUser.Role = UserRole.Worker;
            baseUser.Status = StatusEnum.InActive;
            baseUser.ZIP = "unknown";
            var projectForAll = new Task { Name = "Internal project", EndDate = new DateTime(2050, 1, 1), StartDate = startingDate,
                Leader = baseUser, WorkingHoursEntries = new List<WorkingHoursEntry>()
            };
#if DEBUG
            foreach (var w in WorkingHourEntries)
            {
                projectForAll.WorkingHoursEntries.Add(w);
            }
            
            /*projectForAll.Group = Users;
            projectForAll.Group.Add(user2);
            projectForAll.Group.Add(user3);
            projectForAll.Group.Add(user4);
            projectForAll.Group.Add(user5);
             */
            projectForAll.Group = autoCreatedUsers;
#endif
            context.Projects.Add(new Project { MainTask = projectForAll });
            context.SaveChanges();
            #endregion
            #region Skills
#if DEBUG
            var admin = autoCreatedUsers.Single(u => u.PersonalIdentifier.Equals("1"));
            var Skills = new List<Skill>
            {
                new Skill { Name = "Java" },
                new Skill { Name = "C++" },
                new Skill { Name = "C#" },
                new Skill { Name = "Making Coffee" },
                new Skill { Name = "Self organization" },
                new Skill { Name = "C" },
                new Skill { Name = "Wordpress" },
                new Skill { Name = ".NET" },
                new Skill { Name = "PHP" }
            };
            Skills.ForEach(s => context.Skills.Add(s));
            context.SaveChanges();

            //add 2-3 skills for each user
            foreach (User user in autoCreatedUsers)
            {
                int someNumber = random.Next(100);
                context.User_Skills.Add(new User_Skill { Skill = Skills[someNumber % Skills.Count], User = user, Rating = (user.Position.Equals("Senior Developer")) ? ((someNumber % 2) + 4) : someNumber % 5, ApprovedBy = admin });
                context.User_Skills.Add(new User_Skill { Skill = Skills[(someNumber + 7) % Skills.Count], User = user, Rating = random.Next(5)+1, ApprovedBy = admin });
                if(someNumber % 2 == 0)
                    context.User_Skills.Add(new User_Skill { Skill = Skills[(someNumber + 2) % Skills.Count], User = user, Rating = random.Next(5) + 1, ApprovedBy = admin });
            }
            context.SaveChanges();
            /*
            var userSkill = new User_Skill
            {
                Skill = context.Skills.First(),
                User = user,
                Rating = 5
            };
            context.User_Skills.Add(userSkill);
            context.User_Skills.Add(new User_Skill { Skill = context.Skills.First(), User = user2, Rating = 4, ApprovedBy = user });
            context.User_Skills.Add(new User_Skill { Skill = context.Skills.First(s => s.Name.Equals("C++")), User = user2, Rating = 2, ApprovedBy = user });
            context.SaveChanges();
             */
#endif
            #endregion
            #region Tasks
#if DEBUG
            //Create 3 examples of Projects
            //1st Project
            var projectMainTask = new Task { Name = "Website for White House", EndDate = DateTime.Parse("2013-01-01"), StartDate = startingDate.AddMonths(1), Leader = admin, Status = TaskStatusEnum.InProgress };
            projectMainTask.Group = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Take(5).ToList();
            var subTask1 = new Task { Name = "Requirements", EndDate = DateTime.Parse("2012-04-01"),
                    StartDate = startingDate.AddMonths(1).AddDays(5), Leader = projectMainTask.Group.First(), 
                    Status = TaskStatusEnum.Finished };
            var subTask2 = new Task
            {
                Name = "Architecture",
                EndDate = DateTime.Parse("2012-08-01"),
                StartDate = startingDate.AddMonths(1).AddDays(25),
                Leader = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(10).Take(1) as User,
                Status = TaskStatusEnum.InProgress,
                Requirements = new List<Task> { subTask1 }
            };
            var subTasks = new List<Task>
            {
                subTask1,
                subTask2,
                new Task { Name = "Implementation", EndDate = DateTime.Parse("2012-10-01"), 
                    StartDate = startingDate.AddMonths(2).AddDays(15), 
                    Leader = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(14).Take(1) as User, 
                    Group = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(5).Take(5).ToList(),
                    Status = TaskStatusEnum.Pending, Requirements = new List<Task> { subTask2 } }
            };
            projectMainTask.SubTasks = subTasks;
           
            context.Projects.Add(new Project{ MainTask = projectMainTask } );
            context.SaveChanges();

            //2nd Project
            var project2MainTask = new Task { Name = "Software for Volvo", EndDate = DateTime.Parse("2013-04-01"), StartDate = startingDate.AddMonths(4), Leader = admin, Status = TaskStatusEnum.InProgress };
            project2MainTask.Group = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(8).Take(3).ToList();
            var subTask3 = new Task
            {
                Name = "Requirements",
                EndDate = startingDate.AddMonths(5).AddDays(12),
                StartDate = startingDate.AddMonths(4).AddDays(7),
                Leader = project2MainTask.Group.First(),
                Status = TaskStatusEnum.Finished
            };
            var subTask4 = new Task
            {
                Name = "Architecture",
                EndDate = DateTime.Parse("2012-08-01"),
                StartDate = startingDate.AddMonths(4).AddDays(25),
                Leader = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(20).Take(1) as User,
                Status = TaskStatusEnum.InProgress,
                Requirements = new List<Task> { subTask3 }
            };
            var subTask5 = new Task
            {
                Name = "Implementation",
                EndDate = DateTime.Parse("2013-03-01"),
                StartDate = startingDate.AddMonths(5).AddDays(12),
                Leader = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(17).Take(1) as User,
                Group = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(16).Take(5).ToList(),
                Status = TaskStatusEnum.Pending,
                Requirements = new List<Task> { subTask4 }
            };
            var subTask6 = new Task
            {
                Name = "Testing",
                EndDate = DateTime.Parse("2013-03-01"),
                StartDate = startingDate.AddMonths(5).AddDays(12),
                Leader = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(17).Take(1) as User,
                Group = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(16).Take(5).ToList(),
                Status = TaskStatusEnum.Pending,
                Requirements = new List<Task> { subTask5 }
            };
            project2MainTask.SubTasks = new List<Task>
            {
                subTask3, subTask4, subTask5, subTask6
                
            };

            context.Projects.Add(new Project { MainTask = project2MainTask });
            context.SaveChanges();

            //3rd Project
            var project3MainTask = new Task { Name = "Data Warehouse for XYZ Inc.", EndDate = DateTime.Parse("2013-07-01"), StartDate = startingDate.AddMonths(8), Leader = admin };
            project3MainTask.Group = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(23).Take(4).ToList();
            var subTasks3 = new List<Task>
            {
                new Task { Name = "Requirements", EndDate = startingDate.AddMonths(9).AddDays(12), StartDate = startingDate.AddMonths(8).AddDays(7), Leader = project3MainTask.Group.First() },
                new Task { Name = "Architecture", EndDate = startingDate.AddMonths(13).AddDays(15), StartDate = startingDate.AddMonths(9).AddDays(15), Leader = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(24).Take(1) as User },
                new Task { Name = "Implementation", EndDate = DateTime.Parse("2013-05-01"), StartDate = startingDate.AddMonths(10).AddDays(1), Leader = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(21).Take(1) as User, 
                    Group = autoCreatedUsers.Where(u => u.Status.Equals(StatusEnum.Hired)).Skip(24).Take(3).ToList() }
            };
            project3MainTask.SubTasks = subTasks3;

            context.Projects.Add(new Project { MainTask = project3MainTask });
            context.SaveChanges();
#endif
            #endregion
            #region Reports
#if DEBUG
            byte[] bytes = (new System.Text.ASCIIEncoding()).GetBytes("Hello reports!");
            var report1 = new ReportHeader
            {
                Name = "Just a report",
                CreationDate = DateTime.Now,
                CreatedBy = admin,
                Details =
                    new ReportDetail { FileName = "report.txt", ContentType="text/plain", Data = bytes },
                Task = projectMainTask
            };
            var report2 = new ReportHeader
            {
                Name = "Just another report",
                CreationDate = startingDate.AddMonths(2).AddDays(25),
                CreatedBy = projectMainTask.Group.First(),
                Details =
                    new ReportDetail { FileName = "report2.txt", ContentType = "text/plain", Data = bytes },
                Task = projectMainTask
            };
            context.ReportHeaders.Add(report1);
            context.SaveChanges();
#endif
            #endregion
        }
    }
}
